package com.icesoft.xsnow.common.security.component;

import com.icesoft.xsnow.common.core.constant.enums.ErrorCodeEnum;
import com.icesoft.xsnow.framework.api.util.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: xsnow
 * @description: 自定义AccessDenied异常
 * 处理权限相关异常
 * @author: xuefeng.gao
 * @create: 2019-06-05 13:22
 **/
@Slf4j
@Component
public class XsnowAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseUtils.sendFail(request, response, ErrorCodeEnum.UNAUTHORIZED);
    }
}
